//
//  DetailSaleViewController.m
//  QinrenManagers
//
//  Created by easaa on 15/7/15.
//  Copyright (c) 2015年 easaa. All rights reserved.
//

#import "DetailSaleViewController.h"

@interface DetailSaleViewController ()



@end

@implementation DetailSaleViewController


- (instancetype)init
{
    self = [super init];
    if (self) {
        
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    [self requestData];
    [self creatUI];
}

- (void)requestData {
    EAHttpAPIClient *manager = [EAHttpAPIClient manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSDictionary *parameters = @{@"article_id":self.article_id};
    NSLog(@"广告详情页%@",parameters);
    [manager GetWithParameters:parameters method:@"get.article.list" success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *resposeString ;
        if ([responseObject isKindOfClass:[NSData class]]) {
            resposeString = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
        }else
            resposeString = responseObject;
        
        NSString *jsonString = [DataParser parseString:resposeString];
        id dictionary = [JSONKit jsonToArrayOrDictionary:jsonString];
        NSLog(@"政策详情的dictonary :%@",[dictionary description]);
        
        
        if ([[dictionary objectForKey:@"verification"]intValue] == 1)
        {
            UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, SCREEN_W, 36)];
            
            NSString *title = [dictionary[@"data"][0][@"name"] stringByReplacingOccurrencesOfString:@"+" withString:@""];
            titleLabel.text = title;
            titleLabel.textAlignment = NSTextAlignmentCenter;
            titleLabel.font = [UIFont boldSystemFontOfSize:17];
            
            UIWebView * adDetails = [[UIWebView alloc]initWithFrame:CGRectMake(0, 36, SCREEN_W, SCREEN_H-100)];
            // [adDetails loadHTMLString:dictionary[@"data"][0][@"content"] baseURL:nil];
            
            NSString *str1 = [dictionary[@"data"][0][@"content"] stringByReplacingOccurrencesOfString:@"+" withString:@""];
            
            [adDetails loadHTMLString:str1 baseURL:nil];
            
            
            [self.view addSubview:titleLabel];
            [self.view addSubview:adDetails];
        }
        else
        {
            NSString *error = [dictionary objectForKey:@"error"];
            [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeClear];
            [SVProgressHUD showErrorWithStatus:error];
        }
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeClear];
        [SVProgressHUD showErrorWithStatus:[error localizedDescription]];
    }];
    
}
- (void)creatUI
{
    
}


@end
